<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<meta charset="UTF-8">
	<meta name="decorator" content="default"/>
 
	<title>修改传感器</title>
	
	<script type="text/javascript">	
		$(document).ready(function() {
			  
		});
		
		 
		
		//取得设备名称+出厂编号
		function select_ID(){

			var e_name = document.getElementById("e_name");
			var DeviceName = $("#device option:selected").text();
			e_name.value = DeviceName;
			
		} 
		
		$(function(){
		
		//取消功能
			$("#cancelBtn").click(function(){
			 	window.parent.location.reload(); 
				var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
				parent.layer.close(index); //再执行关闭    
				
			});
			
		//保存功能	 
			$("#confirmBtn").click(function(){
			
			var device = $("#device").val();
				if(device==""||device.trim()==""){
					$.jBox.tip("所属设备不能为空");					
					return false;
				}	
			
				var gwMac = $("#gwMac").val();
				if(gwMac==null||gwMac.trim()==""){
					$.jBox.tip("所属监测仪不能为空");
					return false;
				}	
				
				var type = $("#type").val();
				if(type==null||type.trim()==""){
					$.jBox.tip("类别不能为空");
				
					return false;
				}	
				
				var sensorName = $("#sensorName").val();
				if(sensorName==null||sensorName.trim()==""){
					$.jBox.tip("传感器名称不能为空");
				
					return false;
				}	
			
				var sensorMac = $("#sensorMac").val();
				if(sensorMac==null||sensorMac.trim()==""){
					$.jBox.tip("传感器编号不能为空");
				
					return false;
				}	
				
				var modelNumber = $("#modelNumber").val();
				if(modelNumber==null||modelNumber.trim()==""){
					$.jBox.tip("型号不能为空");
					
					return false;
				}	
			
				var upperTemp = $("#upperTemp").val();
				if(upperTemp==null||upperTemp.trim()==""){
					$.jBox.tip("温度上限不能为空");
				
					return false;
				}	
				
				var lowerTemp = $("#lowerTemp").val();
				if(lowerTemp==null||lowerTemp.trim()==""){
					$.jBox.tip("温度下限不能为空");
					
					return false;
				}	
				
				var measureInterval = $("#measureInterval").val();
				if(measureInterval==null||measureInterval.trim()==""){
				$.jBox.tip("测量周期不能为空");
				
				return false;
				}	
				
				var tempalarmInterval = $("#tempalarmInterval").val();
				if(tempalarmInterval==null||tempalarmInterval.trim()==""){
					$.jBox.tip("温度报警周期不能为空");
					
					return false;
				}	
			
				var poweroffalarmInterval = $("#poweroffalarmInterval").val();
				if(poweroffalarmInterval==null||poweroffalarmInterval.trim()==""){
					$.jBox.tip("断电报警周期不能为空");
				
					return false;
				}	
				
				var multialarmCount = $("#multialarmCount").val();
				if(multialarmCount==null||multialarmCount.trim()==""){
					$.jBox.tip("多级报警次数不能为空");
					
					return false;
				}	
				
				var tempcheckValue = $("#tempcheckValue").val();
				if(tempcheckValue==null||tempcheckValue.trim()==""){
				$.jBox.tip("温度校正值不能为空");
				
				return false;
				}	
				
				var ignoreAlarm = $("#ignoreAlarm").val();
				if(ignoreAlarm==null||ignoreAlarm.trim()==""){
				$.jBox.tip("忽略报警不能为空");
				
				return false;
				}	
				
				window.parent.location.reload();
				var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
				parent.layer.close(index); //再执行关闭  
				
				
					//提交form
				var action="${ctx}/ccseninfo/sensorInfo/updateSensor" ; 
				$("#inputForm").attr('action',action);    //通过jquery为action属性赋值
       			$("#inputForm").submit();    //提交ID为myform的表单 
      
			});
		
		 	/* $('#status').click(function(){
       			 	if($(this).prop("checked")){
			            $(this).val(1);
			        }else{
			            $(this).val(0);
			        }
   			}); */		 
   				 
		});
		
	</script>
	<style type="text/css">
		body{
			color: #000000;
		}
	</style>
</head>
<body>
	<form id="inputForm" class ="inputForm"   method="post">
		<div class="breadcrumb">
			<table class="table table-bordered">	
				<tr>
					<input type = "hidden" id="id" name="id"   size="10" maxlength="20" value="${id}"/> 
					<td><label>所属设备</label>
			   			<span class="help-inline"><font color="red">*</font> </span>
					</td>
					
					<td>
						<span style="font-size:12px;">
							<select id = "device" name = "device" required="true" style="width:220px;" onclick="javascript:select_ID();" >  		
								<c:forEach var="item" items="${deviceList}">
									<option value="${item.DID}">${item.DNAME}</option>
								</c:forEach>			  
							</select>  
						</span>	
						<input type = "hidden" id="e_name" name="e_name"  size="10" maxlength="20" value="${deviceName}"/> 
					</td>	
						
					<td><label>所属监测仪</label>
						<span class="help-inline"><font color="red">*</font> </span>
					</td>
					<td>
						<span style="font-size:12px;">
							<select id = "gwMac" name = "gwMac" required="true" style="width:220px;">    
								<c:forEach var="item" items="${gatewayList}">
									<option value="${item.MAC}">${item.MAC}</option>
								</c:forEach>
							</select>  
						</span>	
					</td>		
				</tr>
				
				<tr>
					<td>
						<label>类别</label>
							<span class="help-inline"><font color="red">*</font> </span>
					</td>			
					<td>	
						<span style="font-size:12px;">
							<select id = "type" name = "type" required="true" style="width:220px;">  
								<option value="01">单温探头</option>  
								<option value="02">单温标签</option>  
								<option value="03">温湿度探头</option>  
								<option value="04">温湿度标签</option>  
							</select>  
						</span>							
					</td>	
							
					<td><label>型号</label>
						<span class="help-inline"><font color="red">*</font> </span>
					</td>
					<td>
						<span style="font-size:12px;">
						<select id = "modelNumber" name = "modelNumber" required="true" style="width:220px;">   
			  			<option value="无线">无线</option>  
			 			<option value="型号1">型号1</option>  
			 			<option value="型号2">型号2</option>  
			 			<option value="便携式">便携式</option>  			
						</select>  
						</span>
					</td>
		</tr>
		<tr>
			<td><label>传感器名</label>
			<span class="help-inline"><font color="red">*</font> </span>
			</td>
				<td>
				<input type="text" id="sensorName" name="sensorName" required="true" size="20" maxlength="20" value="${sensorName}"/> </td>			
			<td><label>传感器编号</label>
			<span class="help-inline"><font color="red">*</font> </span>
			</td>
				<td>
				<input type="text" id="sensorMac" name="sensorMac" required="true" readonly size="20" maxlength="20" value="${sensorMac}"/> </td>	
				</td>
		</tr>
		<tr>
			<td><label>温度下限</label>
			<span class="help-inline"><font color="red">*</font> </span>
			</td>
				<td>
				<input  type="number" id="lowerTemp" name="lowerTemp" required="true" size="20" maxlength="20" value="${lowerTemp}"/> </td>			
			<td><label>温度上限</label>
			<span class="help-inline"><font color="red">*</font> </span>
			</td>
				<td>
				<input  type="number" id="upperTemp" name="upperTemp" required="true" size="20" maxlength="20" value="${upperTemp}"/> 	
				</td> 	
		</tr>
		<tr>
			<td><label>湿度下限</label>
				<span class="help-inline"><font color="red">*</font> </span>
			</td>
				<td>
				<input  type="number" id="lowerHumi" name="lowerHumi" size="20" maxlength="20" value="${lowerHumi}"/> </td>			
			<td><label>湿度上限</label>
				<span class="help-inline"><font color="red">*</font> </span>
			</td>
				<td>
				<input  type="number" id="upperHumi" name="upperHumi" size="20" maxlength="20" value="${upperHumi}"/> 	
				</td> 	
		</tr>
		<tr>
			<td><label>测量周期(分钟)</label>
				<span class="help-inline"><font color="red">*</font> </span>
			</td>
			<td>
				 <input  type="number" id="measureInterval" name="measureInterval" size="20" maxlength="20" value="${measureInterval}"/> 
			</td>
				
			<!-- 通道号未定义 -->
			 <td><label>通道号</label>
				 <span class="help-inline"><font color="red">*</font> </span>
			 </td>
			 
			<td>
				 <span style="font-size:12px;">
				 <select id = "passNumber" name = "passNumber" style="width:220px;">  
				 <option value="1">1</option>   
	  			 <option value="2">2</option>  	
	  			 <option value="3">3</option> 
	  			 <option value="4">4</option> 		
				 </select>  
				 </span>
			</td>
			
		</tr>
		<tr>
			<td><label>温度报警周期(分钟)</label>
				<span class="help-inline"><font color="red">*</font> </span>
			</td>
				<td>
				  <input  type="number" id="tempalarmInterval" name="tempalarmInterval" size="20" maxlength="20" value="${tempalarmInterval}"/> 
				</td> 
			 <td><label>湿度报警周期(分钟)</label>
			 </td>
			<td>
				  <input  type="number" id="humialarmInterval" name="humialarmInterval" size="20" maxlength="20" value="${humialarmInterval}"/> 	
			</td> 
		</tr>
		<tr>			
			 <td><label>断电报警周期(分钟)</label>
				 <span class="help-inline"><font color="red">*</font> </span>
			 </td>
				<td>
					<input  type="number" id="poweroffalarmInterval" name="poweroffalarmInterval" size="20" maxlength="20" value="${poweroffalarmInterval}"/> 				
				 </td> 					
			</select>  
			 <td><label>延迟报警次数</label></td>
				 <td>
				  <input type="number" id="delayalarmCount" name="delayalarmCount" size="20" maxlength="20" value="${delayalarmCount}"/> </td>	
				 </td> 
			
			</td>			 
		</tr>	

		<tr>
			<td><label>多级报警次数</label>
				<span class="help-inline"><font color="red">*</font> </span>
			</td>
				<td>
				  <input type="number" id="multialarmCount" name="multialarmCount" size="20" maxlength="20" value="${multialarmCount}"/> </td>	
				 </td> 
			 <td><label>温度校正值</label>
			 	<span class="help-inline"><font color="red">*</font> </span>
			 </td>
				 <td>
				  <input type="number" id="tempcheckValue" name="tempcheckValue" size="20" maxlength="20" value="${tempcheckValue}"/> </td>	
				 </td> 
		</tr>	
		<tr>
			<td><label>多级报警类型</label>
				<span class="help-inline"><font color="red">*</font> </span>
			</td>
				<td>
				<span style="font-size:12px;">
				 <select id = "multialarmType" name = "multialarmType" style="width:220px;">  
	  			 <option value="本级报警">本级报警</option>  	
	  			 <option value="多级报警">多级报警</option>  		
	  			 <option value="上级报警">上级报警</option>  				
				 </select>  
				 </span>
				 
				</td> 
			 <td><label>忽略报警</label>
				 <span class="help-inline"><font color="red">*</font> </span>
			 </td>
				 <td>
				 <span style="font-size:12px;">
				 <select id = "ignoreAlarm" name = "ignoreAlarm" style="width:220px;">  
	  			 <option value="报警">报警</option>  	
	  			 <option value="不报警">不报警</option>  		
	  			 <option value="报警不发送">报警不发送</option>  				
				 </select>  
				 </span>
				</td> 
		</tr>		
		<tr>				
			<!-- 接种室，方便用户查看 -->
			<td><label>接种室</label>
			</td>
			<!-- <td>
				<input type="text" id="room" name="room" size="20" maxlength="20" value="${room}"/> </td>	
			</td>
			  -->
			<!-- 接种室，下拉选  edit by wangnna 2018-3-13-->
			<td>
				<span style="font-size:12px;">
					<select id = "room" name = "room"  style="width:220px;">
						<option value ="">--请选择--</option>  
						<c:forEach var="item" items="${officeList}">							
							<option value="${item.ID}">${item.NAME}</option>
						</c:forEach>
					</select>  
				</span>	
			</td> 
					
			 <td>
				<label style="margin:5px;"><input id="lowvoltageAlarm"  name="lowvoltageAlarm" type="checkbox" value = "${lowvoltageAlarm}" onclick="this.value=(this.value==1)?0:1"  /><span>低电量报警</span></label>		
			</td>
			<td>
				  <input type="text" id="lowvoltageValue" name="lowvoltageValue" size="20" maxlength="20" value = "${lowvoltageValue}" placeholder="电压低于（V）"/> </td>	
			</td> 
						 
		</tr>			
		<tr>	
			<td>
				<label style="margin:5px;"><input id="status" name="status" type="checkbox" value = "${status}" onclick="this.value=(this.value==1)?0:1" /><span>启用</span></label>		
			</td>
			<td>
				<label style="margin:5px;"><input id="voiceAlarm" name="voiceAlarm" type="checkbox"  value = "${voiceAlarm}" onclick="this.value=(this.value==1)?0:1" /><span>启用语音报警</span></label></td>		
			</td>
			<td>
				<label style="margin:5px;"><input id="interruptAlarm" name="interruptAlarm" type="checkbox" value = "${interruptAlarm}" onclick="this.value=(this.value==1)?0:1" /><span>设备中断报警</span></label></td>
		
			</td>
			<td>
				  <input type="text" id="interruptInterval" name="interruptInterval" value = "${interruptInterval}" size="20" maxlength="20" placeholder="中断时间大于（分钟）"/> </td>	
			</td>
				
				
		</tr>	
			
	</table>			
	</div>

	<div style="margin-right:20px; margin-bottom: 5px;">
		<button  id="confirmBtn" style="margin-top: 5px;margin-left: 500px;"  class="btn btn-primary">确定</button> 
		<button  id = "cancelBtn" style="margin-top: 5px;margin-left: 20px;"   class="btn btn-default">取消</button>
	</div>
	</form>
	
	<script type="text/javascript">
		//下拉框显示对应
		var equipmentId = '${equipmentId}'; 		
		document.getElementById("device").value = equipmentId;//
		
		var deviceName = '${deviceName}'; 
		document.getElementById("e_name").value = deviceName;  // 
		
		var gwMac = '${gwMac}'; 
		document.getElementById("gwMac").value = gwMac;//
		
		var type = '${type}'; 
		document.getElementById("type").value = type;//
		
		var modelNumber = '${modelNumber}'; 
		document.getElementById("modelNumber").value = modelNumber;//
		
		var multialarmType = '${multialarmType}'; 
		document.getElementById("multialarmType").value = multialarmType;//
		
		var ignoreAlarm = '${ignoreAlarm}'; 
		document.getElementById("ignoreAlarm").value = ignoreAlarm;//
		
		//中断报警
		var interruptAlarm = '${interruptAlarm}';
		if("1"==interruptAlarm){
			$("input[name='interruptAlarm']").prop("checked", true);
		} 
		
		//低电压报警
		var lowvoltageAlarm = '${lowvoltageAlarm}';
		if("1"==lowvoltageAlarm){
			$("input[name='lowvoltageAlarm']").prop("checked", true);
		} 
		
		var status = '${status}';
		if("1"==status){
			$("input[name='status']").prop("checked", true);
		} 
		
		var voiceAlarm = '${voiceAlarm}';
		if("1"==voiceAlarm){
			$("input[name='voiceAlarm']").prop("checked", true);
		} 
		
		//下拉框显示对应 接种室
		var room = '${room}'; 		
		document.getElementById("room").value = room;//
		
	</script>
</body>
</html>
